package system

import "time"

// User 系统管理员实体
type User struct {
	ID           uint      `gorm:"primarykey;comment:'主键'"`
	Username     string    `gorm:"not null;default:'';comment:'用户账号''"`
	Nickname     string    `gorm:"default:'';comment:'用户昵称'"`
	Gender       uint8     `gorm:"default:0;comment:'性别: 0=男, 1=女, 2=未知'"`
	Password     string    `gorm:"not null;comment:'用户密码'"`
	PasswordSalt string    `gorm:"default:'';comment:'加密盐巴'"`
	DeptId       uint      `gorm:"comment:'部门ID'"`
	Dept         Dept      `gorm:"foreignKey:DeptId"`
	Avatar       string    `gorm:"default:'';comment:'用户头像'"`
	Mobile       string    `gorm:"default:'';comment:'联系方式'"`
	Email        string    `gorm:"default:'';comment:'用户邮箱'"`
	Roles        []Role    `gorm:"many2many:user_role;foreignKey:ID;joinForeignKey:UserId;References:ID;JoinReferences:RoleId"`
	MultiLogin   uint8     `gorm:"default:0;comment:'多端登录: 0=否, 1=是''"`
	Status       uint8     `gorm:"default:0;comment:'是否禁用: 0=否, 1=是'"`
	CreatedAt    time.Time `gorm:"default:CURRENT_TIMESTAMP; comment:'创建时间'"`
	UpdatedAt    time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; comment:'更新时间'"`
	DeletedAt    time.Time `gorm:"comment:'删除时间'"`
}

// UserRole

type UserRole struct {
	ID     uint `gorm:"primarykey;comment:'主键'"`
	UserId uint `gorm:"not null;comment:'用户ID'"`
	RoleId uint `gorm:"not null;comment:'角色ID'"`
}

// Menu 系统菜单实体
type Menu struct {
	ID         uint      `gorm:"primarykey;comment:'主键'"`
	ParentId   uint      `gorm:"not null;default:0;comment:'父菜单ID'"`
	TreePath   string    `gorm:"default:'';comment:'父节点ID路径'"`
	Children   []Menu    `gorm:"foreignKey:ParentId"`
	Name       string    `gorm:"not null;comment:'菜单名称'"`
	Type       uint8     `gorm:"not null;comment:'权限类型: M=目录，C=菜单，A=按钮''"`
	Path       string    `gorm:"default:'';comment:'路由地址'"`
	Component  string    `gorm:"default:'';comment:'前端组件'"`
	Perm       string    `gorm:"default:'';comment:'权限标识'"`
	Visible    uint8     `gorm:"not null;default:1;comment:'是否显示: 0=否, 1=是'"`
	Icon       string    `gorm:"default:'';comment:'菜单图标'"`
	Sort       uint16    `gorm:"not null;default:0;comment:'菜单排序'"`
	Redirect   string    `gorm:"default:'';comment:'跳转路径'"`
	KeepAlive  uint8     `gorm:"default:0;comment:'是否缓存: 0=否, 1=是''"`
	AlwaysShow uint8     `gorm:"default:0;comment:'只有1个子路由是否始终显示: 0=否, 1=是'"`
	CreatedAt  time.Time `gorm:"default:CURRENT_TIMESTAMP; comment:'创建时间'"`
	UpdatedAt  time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; comment:'更新时间'"`
}

// SystemAuthPerm 系统角色菜单实体
type RoleMenu struct {
	ID     string `gorm:"primarykey;comment:'主键'"`
	RoleId uint   `gorm:"default:0;comment:'角色ID'"`
	MenuId uint   `gorm:"default:0;comment:'菜单ID'"`
}

// SystemAuthRole 系统角色实体
type Role struct {
	ID        uint      `gorm:"primarykey;comment:'主键'"`
	Name      string    `gorm:"not null;comment:'角色名称''"`
	Code      string    `gorm:"default:'';comment:'角色编码'"`
	Status    uint8     `gorm:"default:0;comment:'是否禁用: 0=否, 1=是'"`
	Sort      uint16    `gorm:"default:0;comment:'角色排序'"`
	DataScope uint8     `gorm:"default:0;comment:'数据范围: 0=全部, 1=本部门, 2=本部门及以下, 3=仅本人'"`
	Menus     []Menu    `gorm:"many2many:role_menu;foreignKey:ID;joinForeignKey:RoleId;References:ID;JoinReferences:MenuId"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP; comment:'创建时间'"`
	UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; comment:'更新时间'"`
	DeletedAt time.Time `gorm:"comment:'删除时间'"`
}

// Dept 系统部门实体
type Dept struct {
	ID        uint      `gorm:"primarykey;comment:'主键'"`
	Parentid  uint      `gorm:"not null;default:0;comment:'上级主键'"`
	Name      string    `gorm:"not null;default:'';comment:'部门名称''"`
	TreePath  string    `gorm:"default:'';comment:'父节点id路径'"`
	Sort      uint16    `gorm:"default:0;comment:'排序编号'"`
	Status    uint8     `gorm:"default:1;comment:'是否停用: 0=否, 1=是'"`
	CreatedBy uint      `gorm:"not null;comment:'创建人'"`
	UpdatedBy uint      `gorm:"default:0;comment:'更新人'"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP; comment:'创建时间'"`
	UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; comment:'更新时间'"`
	DeletedAt time.Time `gorm:"comment:'删除时间'"`
}

// SystemAuthPost 系统岗位管理
type Position struct {
	ID        uint      `gorm:"primarykey;comment:'主键'"`
	DeptId    uint      `gorm:"not null;default:0;comment:'部门ID'"`
	Dept      Dept      `gorm:"foreignKey:DeptId"`
	Code      string    `gorm:"default:'';comment:'岗位编码''"`
	Name      string    `gorm:"default:'';comment:'岗位名称''"`
	Remarks   string    `gorm:"default:'';comment:'岗位备注''"`
	Sort      uint16    `gorm:"default:0;comment:'岗位排序'"`
	Status    uint8     `gorm:"default:0;comment:'是否停用: 0=否, 1=是'"`
	CreatedAt time.Time `gorm:"default:CURRENT_TIMESTAMP; comment:'创建时间'"`
	UpdatedAt time.Time `gorm:"column:updated_at;default:CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP; comment:'更新时间'"`
	DeletedAt time.Time `gorm:"comment:'删除时间'"`
}

// SystemLogLogin 系统登录日志实体
type LogAuth struct {
	ID        uint      `gorm:"primarykey;comment:'主键'"`
	UserId    uint      `gorm:"default:0;comment:'管理员ID'"`
	Username  string    `gorm:"default:'';comment:'登录账号'"`
	Ip        string    `gorm:"default:'';comment:'登录地址'"`
	Os        string    `gorm:"default:'';comment:'操作系统'"`
	Browser   string    `gorm:"default:'';comment:'浏览器'"`
	Status    uint8     `gorm:"default:0;comment:'操作状态: 1=成功, 0=失败'"`
	CreatedAt time.Time `gorm:"autoCreateTime;comment:'创建时间'"`
}

// SystemLogOperate 系统操作日志实体
type LogOperate struct {
	ID         uint      `gorm:"primarykey;comment:'主键'"`
	OperatorId uint      `gorm:"default:0;comment:'操作人ID'"`
	Type       string    `gorm:"default:'';comment:'请求类型: GET/POST/PUT'"`
	Title      string    `gorm:"default:'';comment:'操作标题'"`
	Ip         string    `gorm:"default:'';comment:'请求IP'"`
	Url        string    `gorm:"default:'';comment:'请求接口'"`
	Method     string    `gorm:"default:'';comment:'请求方法'"`
	Args       string    `gorm:"comment:'请求参数'"`
	Error      string    `gorm:"comment:'错误信息'"`
	Status     uint8     `gorm:"default:0;comment:'执行状态: 1=成功, 2=失败'"`
	StartTime  int64     `gorm:"default:0;comment:'开始时间'"`
	EndTime    int64     `gorm:"default:0;comment:'结束时间'"`
	TaskTime   int64     `gorm:"default:0;comment:'执行耗时'"`
	CreatedAt  time.Time `gorm:"autoCreateTime;comment:'创建时间'"`
}

// DictData 字典数据实体
type Dict struct {
	ID        uint      `gorm:"primarykey;comment:'主键'"`
	GId       uint      `gorm:"comment:'字典类型编码'"`
	DictGroup DictGroup `gorm:"foreignKey:GId"`
	Name      string    `gorm:"default:'';comment:'键名''"`
	Value     string    `gorm:"default:'';comment:'数值'"`
	Sort      uint16    `gorm:"default:0;comment:'排序'"`
	Status    uint8     `gorm:"default:1;comment:'字典状态: 0=停用, 1=正常'"`
	Defaulted uint8     `gorm:"default:0;comment:'是否默认: 0=否, 1=是'"`
	Remark    string    `gorm:"default:'';comment:'备注'"`
	CreatedAt time.Time `gorm:"autoCreateTime;comment:'创建时间'"`
	UpdatedAt time.Time `gorm:"autoUpdatedAt;comment:'更新时间'"`
	DeletedAt time.Time `gorm:"autoDeletedAt; comment:'删除时间'"`
}

// DictType 字典类型实体
type DictGroup struct {
	ID         uint      `gorm:"primarykey;comment:'主键'"`
	DictName   string    `gorm:"default:'';comment:'字典名称''"`
	DictType   string    `gorm:"default:'';comment:'字典类型'"`
	DictRemark string    `gorm:"default:'';comment:'字典备注'"`
	DictStatus uint8     `gorm:"default:1;comment:'字典状态: 0=停用, 1=正常'"`
	CreatedAt  time.Time `gorm:"autoCreateTime;comment:'创建时间'"`
	UpdatedAt  time.Time `gorm:"autoUpdatedAt;comment:'更新时间'"`
	DeletedAt  time.Time `gorm:"comment:'删除时间'"`
}
